package com.boco.transnms.server.dao.traph;

import com.boco.transnms.server.dao.base.GenericDAO;
import com.boco.transnms.common.dto.base.BoActionContext;
import com.boco.transnms.common.dto.base.DboCollection;
import com.boco.transnms.common.dto.ReplySmsInfo;
import com.boco.transnms.common.dto.base.DataObjectList;
/**
 * <p>Title: TransNMS</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: Boco Inter-Telecom INC</p>
 *
 * @author not attributable
 * @version 1.0
 */
public class AttSheetReceiptSMSAlertsDAO extends GenericDAO{
    public AttSheetReceiptSMSAlertsDAO() {
        super("AttSheetReceiptSMSAlertsDAO");
    }

    public ReplySmsInfo getReplySmsInfo(BoActionContext actionContext) throws Exception {
        ReplySmsInfo replySmsInfo = null;
        String sql = "select * from REPLY_SMS_INFO";
        DboCollection dbo = super.selectDBOs(sql, new ReplySmsInfo());
        if(dbo!=null && dbo.size()>0){
            replySmsInfo = (ReplySmsInfo) dbo.getAttrField(ReplySmsInfo.CLASS_NAME, 0);
            setReplySmsInfoLabelCn(replySmsInfo);
        }
        return replySmsInfo;
    }

    public ReplySmsInfo updateReplySmsInfo(BoActionContext actionContext,ReplySmsInfo replySmsInfo) throws Exception {
        String sql = "DELETE FROM REPLY_SMS_INFO";
        super.execSql(sql);
        super.createObject(actionContext, replySmsInfo);
        return getReplySmsInfo(actionContext);
    }

    private void setReplySmsInfoLabelCn(ReplySmsInfo replySmsInfo){
        String replyFilterCon = replySmsInfo.getReplyFilterCondition();
        if(replyFilterCon!=null && !replyFilterCon.equals("")){
            String sql1 = "SELECT FILTER_NAME FROM SHEET_FILTER_INFO WHERE CUID='" + replyFilterCon + "'";
            DataObjectList dbos = null;
            try {
                dbos = super.selectDBOs(sql1, new Class[] {String.class});
                if(dbos!=null && dbos.size()>0){
                    replySmsInfo.setAttrValue("replyFilterConName",(dbos.get(0)).getAttrString("1"));
                }
            } catch (Exception ex) {
            }
        }
        String unReplyFilterCon = replySmsInfo.getUnreplyFilterCondition();
        if(unReplyFilterCon!=null && !unReplyFilterCon.equals("")){
            String sql1 = "SELECT FILTER_NAME FROM SHEET_FILTER_INFO WHERE CUID='" + unReplyFilterCon + "'";
            DataObjectList dbos = null;
            try {
                dbos = super.selectDBOs(sql1, new Class[] {String.class});
                if(dbos!=null && dbos.size()>0){
                    replySmsInfo.setAttrValue("unReplyFilterConName",(dbos.get(0)).getAttrString("1"));
                }
            } catch (Exception ex) {
            }
        }
    }
}
